-----------------------------------------------------------------------------
-- 羁绊小红点逻辑处理  入口小红处理(所有英雄)
--
---------------
-- Author: wd
-----------------------------------------------------------------------------
require "Common/define"
require "Logic/Config"
require "Common/functions"

RedDotsHeroFetterRewardHandler ={};
local this = RedDotsHeroFetterRewardHandler;

function RedDotsHeroFetterRewardHandler.init()
    CloseEvent(Config.EventType.Fresh_FetterAward, this.update)
    ListenEvent(Config.EventType.Fresh_FetterAward, this.update)
    CloseEvent(Config.EventType.Fresh_FetterDetial, this.update)
    ListenEvent(Config.EventType.Fresh_FetterDetial, this.update)

    return this;
end

function RedDotsHeroFetterRewardHandler.getFlag(...)
    if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.Restrain,false) then
        local fetterAwardCfg = G.dataTable["t_trammelpointreward"];
        local g_awardValue = logicMgr.HeroManager.GetHeroFetterAwardValue()
        local hadAwardTable = logicMgr.HeroManager.GetHeroFetterHadAwardList()
        for k, v in pairs(fetterAwardCfg) do
            if g_awardValue >= v["f_Point"] and hadAwardTable[v["f_Id"]] == nil then
                return Config.RedDotsFlagState.Needful;
            end
        end
    end
    return Config.RedDotsFlagState.None
end

--- 计算羁绊奖励点
function RedDotsHeroFetterRewardHandler.CalculateAwardValue()
    local acount = 0
    local fetterTable = logicMgr.HeroManager.GetHeroFetterAwardValue()
    for _, fetterID in pairs(fetterTable) do
        local cfgInfo = G.dataTable["t_trammel"][tostring(fetterID)]
        if cfgInfo then
            acount = acount + cfgInfo["f_TrammelPoint"] or 0
        end
    end
    return acount
end

function RedDotsHeroFetterRewardHandler.update()
    RedDotsManager.addBroadcast(Config.RedDotsType.HeroFetterReward);
end